/*
storage user auth and token
*/

class AuthInfo {
  constructor(userId, repoId, token) {
    this.userId = userId;
    this.repoId = repoId;
    this.token = token;
  }
}

const KEY = "ESYNC-STORAGE";

export function loadAuthInfo() {
  let rs = window.localStorage.getItem(KEY);
  if(!!!rs) {
    return null;
  }
  let obj = JSON.parse(rs);
  return new AuthInfo(obj.user_id, obj.repo_id, obj.token);
}

export function saveAuthInfo(userId, token) {
  localStorage.setItem(KEY, JSON.stringify({
    user_id: userId,
    token: token,
  }));
}
